<?php
class validationFormation extends CI_Controller {

	
	public function lister($numFormation) // 
	{
            if (($this->session->userdata('type') == 'admin'))
                {
                    $this->load->view('headerAdmin.php');
                    $this->load->model('modeleFormationAdmin');
                    $data['detailFormation'] = $this->modeleFormationAdmin->detailFormation($numFormation);
                    $this->load->view('v_detailFormation', $data);
                }
                else
                {
                    redirect('authentification/authentifier/accueil');
                }
           
        }
        
        public function valider(){
            if (($this->session->userdata('type') == 'admin'))
                {
                    $session = $_POST['session'];
                    $matricules = $_POST['tabChecked'];
                    $tabMat= explode(",", $matricules);
                    $this->load->model('modeleClientAdmin');
                    $this->load->model('modeleSessionAdmin');
                    foreach ($tabMat as $key => $matricule){
                        $client = $this->modeleClientAdmin->getClientByMatricule($matricule);
                        $client = $client->row(0);
                        $this->modeleClientAdmin->valideSessionMatricule($matricule, $session);
                        $detailSession = $this->modeleSessionAdmin->detailSession($session);
                        $detailSession = $detailSession->row(0);
                        mail($client->email, "Validation formArmor", 'Vous avez été validé pour la session numero '.$session.' pour la formation "'.$detailSession->niveauform.' '.$detailSession->libelleform.'" à la date : '.date("d-m-Y", strtotime($detailSession->datedebut)));
                    }
                    
                 }
                else
                {
                    redirect('authentification/authentifier/accueil');
                }
            }
            
            public function annuler(){
            if (($this->session->userdata('type') == 'admin'))
                {
                    $session = $_POST['session'];
                    $matricules = $_POST['tabChecked'];
                    $motif = $_POST['motif'];
                    $tabMat= explode(",", $matricules);
                    $this->load->model('modeleClientAdmin');
                    $this->load->model('modeleSessionAdmin');
                    foreach ($tabMat as $key => $matricule){
                        $client = $this->modeleClientAdmin->getClientByMatricule($matricule);
                        $client = $client->row(0);
                        $this->modeleClientAdmin->annuleSessionMatricule($matricule, $session);
                        $this->modeleSessionAdmin->decNbInscrits($session);
                        $detailSession = $this->modeleSessionAdmin->detailSession($session);
                        $detailSession = $detailSession->row(0);
                        mail($client->email, "Annulation formArmor", 'Vous avez été annulé pour la session numero '.$session.' pour la formation "'.$detailSession->niveauform.' '.$detailSession->libelleform.'" à la date : '.date("d-m-Y", strtotime($detailSession->datedebut)).'. Motif : '.$motif);
                    }
                    
                 }
                else
                {
                    redirect('authentification/authentifier/accueil');
                }
            }
            
            public function validerFin(){
                if (($this->session->userdata('type') == 'admin')){
                    $session = $_POST['session'];
                    $matricules = $_POST['tabMat'];
                    $tabMat= explode(",", $matricules);
                    $this->load->model('modeleSessionAdmin');
                    $this->load->model('modelePlanAdmin');
                    $this->modeleSessionAdmin->closeSession($session);
                    foreach ($tabMat as $key => $matricule){
                        $detailSession = $this->modeleSessionAdmin->detailSession($session);
                        $detailSession = $detailSession->row(0);
                        $this->modelePlanAdmin->planEffectue($matricule, $detailSession->libelleform, $detailSession->niveauform);
                    }
                    
                    
                }else{
                    redirect('authentification/authentifier/accueil');
                }
            }
}
